package com.wf.classRoomTest.staticcc;

import java.util.concurrent.TimeUnit;

/**
 * @Author fengqq
 * @Description  没有代理的做法 ；核心业务+日志追踪 缺点：代码的维护性很差
 * @Date 2024/6/19  15:16
 */
public class UserLogService implements IUserService{
    @Override
    public boolean login(String username, String password) {
        System.out.println("开始日志记录，追踪的方法是login,username="+username);
        long start = System.currentTimeMillis();
        boolean flag = false;
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if("admin".equals(username) && "admin".equals(password)){
            flag = true;
        }
        long end = System.currentTimeMillis();
        System.out.println("结束日志追踪，，追踪的方法是login,此方法耗时="+(end-start)/1000.0+"s");
        return flag;
    }

    @Override
    public boolean register(String username, String password, int age) {
        System.out.println("开始日志记录，追踪的方法是register,username="+username);
        long start = System.currentTimeMillis();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("插入用户数据中....username="+username+",age="+age);
        long end = System.currentTimeMillis();
        System.out.println("结束日志追踪，，追踪的方法是register,此方法耗时="+(end-start)/1000.0+"s");
        return true;
    }
}
